<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="Doc.css" rel="stylesheet"/>
<title>TreeGrid - Deleting rows</title>
</head>
<body>
<div class="Doc">


<h1>Row deleting</h1>
<p>TreeGrid documentation</p>

When a user deletes row, the row is <u>not</u> physically removed. The deleted row is marked as <a href="#IDeleted">Deleted</a> and is hidden or colored red depending on <a href="#CfgShowDeleted">ShowDeleted</a>.<br />
The deleted row can be still undeleted, by a user if it is visible or by API.<br /> 
After the changes are uploaded to server and server accepts the changes, the deleted row is physically removed from grid and its data.<br />

<!-- Deleting -->
<a name="CfgDeleting"></a>
<div class="XML">
   <u></u> <b>&lt;Cfg></b> <i>bool</i>
   <h4>Deleting</h4> <s>[1]</s>
</div>
If rows can be deleted from grid.<br />
If set to 0, it disables Panel <a href="#PanelDelete">Delete</a> button, the deleting actions and <a href="#DeleteRow">DeleteRow</a> method. The <a href="#DeleteRowT">DeleteRowT</a> and <a href="#RemoveRow">RemoveRow</a> are still working.<br />

<!-- ShowDeleted -->
<a name="CfgShowDeleted"></a>
<div class="XML">
   <u></u> <b>&lt;Cfg></b> <i>bool</i>
   <h4>ShowDeleted</h4> <s>[1] &nbsp; Saved to cookies</s>
</div>
If deleted rows and columns are visible and colored.<br /> 
If set to <b>1</b>, deleted rows and columns are still visible and can be undeleted. The deleted rows are colored in red, it can be changed in Grid.css.<br />
If set to <b>0</b>, deleted rows and columns are hidden and cannot be undeleted by a user.<br />
Setting to <b>1</b> when <b>AutoUpdate</b> is true has no effect - the rows are immediately deleted.<br />

<!-- DeleteMessage -->
<a name="CfgDeleteMessage"></a>
<div class="XML">
   <u>new <b>12.0</b></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>DeleteMessage</h4> <s>[1]</s>
</div>
If the confirmation message for deleting row, selected rows, column and selected columns will be shown.<br />
<b>0</b> - never, <b>1</b> - only if <a href="#CfgShowDeleted">ShowDeleted</a> is on, <b>2</b> always.<br />

<!-- CanDelete -->
<a name="ICanDelete"></a>
<div class="XML">
   <u></u> <b>&lt;I></b> <i>bool</i>
   <h4>CanDelete</h4> <s>[1/0]</s>
</div>
If the row can be deleted.<br /> 
By default variable rows can be deleted and fixed rows cannot. Deleting fixed rows is not good idea, fixed rows cannot be added.<br />

<!-- CanDelete -->
<a name="HeaderCanDelete"></a>
<div class="XML">
   <u><i>upd <b>12.0</b></i></u> <b>&lt;Header></b> <i>bool</i>
   <h4>CanDelete</h4> <s>[1]</s>
</div>
<b>Deprecated <i>since 12.0</i>. Use Panel <a href="TypePanel.htm#CButtons">Buttons</a> or Panel value instead to define the panel buttons for header row.</b><br />
If the Panel <b>DeleteAll</b> button is enabled. Header row itself can never be deleted.<br />

<!-- Deleted -->
<a name="IDeleted"></a>
<div class="XML">
   <u></u> <b>&lt;I></b> <i>bool</i>
   <h4>Deleted</h4> <s>[0] &nbsp; Uploaded to server, supports Undo</s>
</div>
It is set to <b>1</b> when the row has been deleted.<br /> 
The row is hidden if <tt><a href="#CfgShowDeleted">ShowDeleted</a>='0'</tt> or visible and colored red (by default setting in Grid.css) when <tt><a href="#CfgShowDeleted">ShowDeleted</a>='1'</tt>.<br />
If the row is shown, it can be undeleted. Child row of deleted parent cannot be undeleted.<br />
When user deletes row, all its children are automatically deleted to. When user undeletes the parent, all its children are undeleted too, except they were deleted directly.<br />
In API, deleted children due its parent deletion has <tt>Deleted='<b>2</b>'</tt>.<br />
The deleted row is ignored in summary calculations. The deleted row cannot be moved and does not accept children by dragging or adding.<br />
After uploading changes to server or calling <a href="DataUpload.htm#AcceptChanges">AcceptChanges</a> the deleted row is physically removed from grid.<br />

<!-- Delete -->
<a name="PanelDelete"></a>
<div class="XML">
   <u></u> <b>&lt;C></b> <i>bool</i>
   <h4>Delete</h4> <s>[1]</s>
</div>
If the default Panel button <b>Delete</b> is visible. This button is hidden also if <tt>&lt;Cfg <a href="#CfgDeleting">Deleting</a>="0"/></tt>. This button is inactive when the row has <tt><a href="#ICanDelete">CanDelete</a>='0'</tt>.<br />
Click to this button deletes row or undeletes deleted row.<br />
<i>Used only if the Panel <a href="TypePanel.htm#CButtons">Buttons</a> and the cell value are <u>not</u> set.</i><br />

<!-- OnRowDelete -->
<a name="OnRowDelete"></a>
<div class="API">
   <u></u> <b>API event</b> <i>void</i>
   <h4>OnRowDelete</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>TRow</i> <b>row</b>, <i>int</i> <b>type</b>)</s>
</div>
Called before the row is deleted. Called after the row is marked as <a href="#IDeleted">Deleted</a>, but before it is hidden or colored.<br />
Fires for every row being deleted, even for deleted children of deleted parent. First are deleted children and after them the parent.<br />
<i>type</i> = 1 delete row, 2 delete row because its parent is deleted.<br /> 
<i>If row is removed by <a href="#RemoveRow">RemoveRow</a> ( ), event is not fired!</i><br />

<!-- OnRowUndelete -->
<a name="OnRowUndelete"></a>
<div class="API">
   <u></u> <b>API event</b> <i>void</i>
   <h4>OnRowUndelete</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>TRow</i> <b>row</b>)</s>
</div>
Called before the row is undeleted. Called after the row has cleared its <a href="#IDeleted">Deleted</a> attribute, but before it is shown or colored.<br />
Fires for every row being undeleted, even for undeleted children of undeleted parent. First are undeleted children and after them the parent.<br />

<!-- OnCanRowDelete -->
<a name="OnCanRowDelete"></a>
<div class="API">
   <u><i>upd 11.0</i></u> <b>API event</b> <i>int</i>
   <h4>OnCanRowDelete</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>TRow</i> <b>row</b>, <i>int</i> <b>type</b>, <i>TRow[ ]</i> <b>rows</b>)</s>
</div>
Called before row is deleted or undeleted. Called to find out if and how can the row be deleted or undeleted. It is not called for its children.<br />
<b>type</b> = <b>0</b> - cannot delete, <b>1</b> - user must confirm deleting, <b>2</b> - delete, <b>3</b> - undelete.<br /> 
Return new type. Or return the <b>type</b> to not change the behavior. Returning <b>2</b> for deleted row and <b>3</b> for not deleted row has no effect.<br />
If fires when deleting selected rows, <b>type</b> = 1 has no meaning.<br />
<i>(Since 11.0)</i> <b>rows</b> are set if called on deleting selected rows and contain all the selected rows to delete or undelete. For every of these rows is called the OnCanRowDelete.<br />

<!-- OnDeleteAll -->
<a name="OnDeleteAll"></a>
<div class="API">
   <u></u> <b>API event</b> <i>bool</i>
   <h4>OnDeleteAll</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>int</i> <b>type</b>)</s>
</div>
Called before all selected rows are deleted or undeleted. Return true to suppress the action.<br />
<b>type</b> = <b>0</b> undelete, <b>1</b> delete, <b>2</b> remove.<br /> 
<i>Remember, this event can be called more times, depending on Actions settings for event ClickHeaderDelete.</i><br />

<!-- DeleteRow -->
<a name="DeleteRow"></a>
<div class="API">
   <u><i>upd <b>12.0</b></i></u> <b>API method</b> <i>bool</i>
   <h4>DeleteRow</h4>
   <s>(<i>TRow</i> <b>row</b>, <i>int</i> <b>type</b>, <i>bool</i> <b>test</b> = 0)</s>
</div>
Deletes / undeletes row from grid. Displays changes. Prepares deleting and calls <a href="#DeleteRowT">DeleteRowT</a> ( ).<br />
<b>type</b> =  <b>1</b> - delete + confirm dialog, <b>2</b> - delete, <b>3</b> - undelete.<br /> 
Deletes or undeletes row with its children. Only marks rows as deleted.<br />
Returns true if the deletion was done.<br />
<i>(Since 12.0)</i> If set <b>test</b> = <b>1</b>, does not delete row, only tests if it is possible, but does <u>not</u> show confirm message, takes it as confirmed.<br />

<!-- DeleteRowT -->
<a name="DeleteRowT"></a>
<div class="API">
   <u></u> <b>API method</b> <i>void</i>
   <h4>DeleteRowT</h4>
   <s>(<i>TRow</i> <b>row</b>, <i>int</i> <b>type</b>, <i>bool</i> <b>noshow</b> = false)</s>
</div>
Deletes / undeletes row from grid. Displays changes. <b>type</b> =  <b>2</b> - delete, <b>3</b> - undelete.<br />
Deletes or undeletes row with its children.<br />

<!-- RemoveRow -->
<a name="RemoveRow"></a>
<div class="API">
   <u>renamed <b>6.0</b></u> <b>API method</b> <i>void</i>
   <h4>RemoveRow</h4>
   <s>(<i>TRow</i> <b>row</b>)</s>
</div>
Physically removes the row from grid and data. <i>The row is really deleted, not just marked!</i> For marking row as Deleted use <a href="#DeleteRow">DeleteRow</a>() instead.<br />
Deleted rows are not in output data, thus server cannot see which rows were deleted (only by comparing with original data).<br />
<i>Only variable row can be removed.</i><br />
<i>Remember, removed row cannot be used in any API function, especially take care in loops, you cannot use GetNext / GetPrev functions with removed row.</i><br />

<!-- OnRowRemove -->
<a name="OnRowRemove"></a>
<div class="API">
   <u>new <b>16.2</b></u> <b>API event</b> <i>bool</i>
   <h4>OnRowRemove</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>TRow</i> <b>row</b>, <i>int</i> <b>type</b>)</s>
</div>
Called before the row is physically removed. It is called for every row remove in grid, including temporary rows.<br />
Return true to not remove the row.<br />

<!-- DeleteRows -->
<a name="DeleteRows"></a>
<div class="API">
   <u>new <b>12.0</b></u> <b>API method</b> <i>int</i>
   <h4>DeleteRows</h4>
   <s>(<i>TRow[ ]</i> <b>rows</b>, <i>int</i> <b>del</b> = 1)</s>
</div>
Deletes (<b>del</b> = <b>1</b>), or undeletes (<b>del</b> = <b>0</b>) or removes (<b>del</b> = <b>2</b>) all given rows in grid.<br />
Returns final count of affected rows.<br />

<!-- Action DeleteRow -->
<a name="ActionsDeleteRow"></a>
<div class="ACT">
   <u></u> <b>&lt;Actions></b> <i></i>
   <h4>DeleteRow <i>...<a href="Events.htm#Suffix">FSARO</a></i></h4>
   <s>Attached to <b>OnDel</b> and <b>OnClickPanelDelete</b> events</s>
</div>
Deletes actual or focused row or first selected row, the row is marked as <a href="#IDeleted">Deleted</a>.<br />
It always deletes only one row, but does not require the row to be the only focused or selected, it is the difference to DeleteRowsO.<br />

<!-- Action UndeleteRow -->
<a name="ActionsUndeleteRow"></a>
<div class="ACT">
   <u></u> <b>&lt;Actions></b> <i></i>
   <h4>UndeleteRow <i>...<a href="Events.htm#Suffix">FSARO</a></i></h4>
   <s>Attached to <b>OnDel</b> and <b>OnClickPanelDelete</b> events</s>
</div>
Undeletes actual or focused row.<br /> 
It is used only if the deleted rows are visible (<tt>&lt;Cfg <a href="#CfgShowDeleted">ShowDeleted</a>='1'/></tt>).<br />
To invert deletion use action setting <tt>"DeleteRow OR UndeleteRow".</tt><br />

<!-- Action RemoveRow -->
<a name="ActionsRemoveRow"></a>
<div class="ACT">
   <u></u> <b>&lt;Actions></b> <i></i>
   <h4>RemoveRow <i>...<a href="Events.htm#Suffix">FSARO</a></i></h4>
   <s>Not attached to any event</s>
</div>
Physically removes the actual or focused  row. The row will no longer exist in grid and cannot be updated to server!<br />

<!-- Action DeleteRows -->
<a name="ActionsDeleteRows"></a>
<div class="ACT">
   <u>new <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>DeleteRows <i>...<a href="Events.htm#Suffix">FSARCWO</a></i></h4>
   <s>Not attached to any event</s>
</div>
Deletes focused or selected or actual rows, the rows are marked as <a href="#IDeleted">Deleted</a>.<br />
<i>This action can be asynchronous!</i><br />

<!-- Action UndeleteRows -->
<a name="ActionsUndeleteRows"></a>
<div class="ACT">
   <u>new <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>UndeleteRows <i>...<a href="Events.htm#Suffix">FSARCWO</a></i></h4>
   <s>Not attached to any event</s>
</div>
Undeletes focused or selected or actual rows.<br />
<i>This action can be asynchronous!</i><br />

<!-- Action RemoveRows -->
<a name="ActionsRemoveRows"></a>
<div class="ACT">
   <u>new <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>RemoveRows <i>...<a href="Events.htm#Suffix">FSARCWO</a></i></h4>
   <s>Not attached to any event</s>
</div>
Physically removes focused or selected or actual rows. The rows will no longer exist in grid and cannot be updated to server!<br />
<i>This action can be asynchronous!</i><br />

<!-- Action DeleteSelected -->
<a name="ActionsDeleteSelected"></a>
<div class="ACT">
   <u>chg <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>DeleteSelected</h4>
   <s>Attached to <b>OnCtrlDel</b> and <b>OnClickHeaderDelete</b> events</s>
</div>
Deletes all selected rows. It fails if there is no selected row or all selected rows are deleted.<br />
It does not delete selected children of selected parents - it is the difference to DeleteRowsS.<br />
<i>This action can be asynchronous!</i><br />

<!-- Action UndeleteSelected -->
<a name="ActionsUndeleteSelected"></a>
<div class="ACT">
   <u>chg <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>UndeleteSelected</h4>
   <s>Attached to <b>OnCtrlDel</b> and <b>OnClickHeaderDelete</b> events</s>
</div>
Undeletes all selected rows. It fails if there is no selected deleted row. Or <i>(Since 12.0)</i> fails if the actual row is not selected and is Kind=Data row.<br />
It is used only if the deleted rows are visible (<tt>&lt;Cfg <a href="#CfgShowDeleted">ShowDeleted</a>='1'/></tt>).<br />
To invert deletion use "UndeleteSelected OR DeleteSelected" - <i>remember, here it depends on the order!</i><br />
<i>This action can be asynchronous!</i><br />

<!-- Action RemoveSelected -->
<a name="ActionsRemoveSelected"></a>
<div class="ACT">
   <u>chg <b>12.0</b></u> <b>&lt;Actions></b> <i></i>
   <h4>RemoveSelected</h4>
   <s>Not attached to any event</s>
</div>
Physically removes all selected rows. The rows will no longer exist in grid and cannot be updated to server!<br />
<i>This action can be asynchronous!</i><br />

</div>
</body>	
</html>